package com.xcity.db.entity;

import com.xcity.db.mapper.RankingMapper;

import naga.x.game.time.TimeUpdater;

@SuppressWarnings("serial")
public class Ranking extends AbstractEntity<RankingMapper>/* implements Comparable<Ranking>*/ {

	protected int id; // 标识符(自增)
	protected long playerId; // 玩家id
	protected byte type; // 排名类型(资产排名、等级排名、魅力...)
	protected long value; // 用于计算排名的数值
	protected long time; // 数据更新时间
	
	protected int index;
	protected long bufferValue;
	
	public Ranking() {}
	
	public Ranking(Player player, byte type, int value) {
		this(player, type, (long) value);
	}
	
	public Ranking(Player player, byte type, long value) {
		this(player.getId(), type, value);
	}
	
	public Ranking(long playerId, byte type, long value) {
		this.state = EntityState.INSERT;
		this.playerId = playerId;
		this.type = type;
		this.value = this.bufferValue = value;
		this.index = -1;
		this.time = TimeUpdater.getInstance().now();
	}

	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public long getPlayerId() {
		return playerId;
	}

	public void setPlayerId(long playerId) {
		this.playerId = playerId;
	}

	public byte getType() {
		return type;
	}

	public void setType(byte type) {
		this.type = type;
	}

	public long getValue() {
		return value;
	}

	public void setValue(long value) {
		this.value = this.bufferValue = value;
	}

	public long getTime() {
		return time;
	}

	public void setTime(long time) {
		this.time = time;
	}

	public int getIndex() {
		return index;
	}

	public void valueChanged(long newVal) {
		this.bufferValue = newVal;
		this.time = TimeUpdater.getInstance().now();
	}
	
	public long getBufferValue(){
		return bufferValue;
	}
	
	public void fireValueChanged() {
		this.value = this.bufferValue;
	}
	
	public void fireValueChanged(int index) {
		this.index = index;
		this.value = this.bufferValue;
	}

//	@Override
//	public int compareTo(Ranking o) {
//		if (bufferValue == o.bufferValue) {
//			return id > o.id ? 1 : -1;
//		}
//		return bufferValue < o.bufferValue ? 1 : -1;
//	}
	
}
